<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>

</body>

<!------------------------------ 预编译时期this指向window -------------------------------------------------------------->
<!------------------------------ new一个对象时this指向Object.create(构造函数.prototype) --------------------------------->
<!------------------------------ 对象调用时this指向调用者 --------------------------------------------------------------->
<script type="text/html">
    //
    function Some() {
    console.log(this.name);
    this.func = function () {
    console.log(this.name);
    }
    }

    var f = (function a() {
    var str = 'ao';
    return function () {
    // var str = 'ao';
    console.log(this.str);
    }
    })();
    Some.prototype.name = 'some';
    Object.prototype.name = 'object';
    var str = 'global';
    var name = 123;
    //--------
    f();
    Some();
    var x = new Some();
    Some.prototype.name = 'someSome';
    x.func();
    x.name = 666;
    x.func();
</script>

<!------------------------------ call()&apply()改变this指向为其传入的第一个参数------------------------------------------->
<script type="text/html">
    //
    function Father(age) {
    this.age = age;
    console.log(this);
    }

    function Son(name, age) {
    Father.call(this, age);
    this.name = name;
    console.log(this);
    }

    var f = new Father(50);
    console.log('-----------');
    var s = new Son('wey', 23);
</script>

</html>